//
//  BlockHeader.swift
//  ZYA
//
//  Created by 邱仙凯 on 2024/12/3.
//  Copyright © 2024 zwb. All rights reserved.
//

import UIKit

class ComDynNavView: UIView {
    lazy var searchBg: UIView = {
        let v = UIView()
         return v
    } ()
    lazy var titleLab: UILabel = {
        let v = UILabel()
        v.font = UIFont.boldSystemFont(ofSize: 22)
         return v
    } ()
 
    lazy var searchButton: UIButton = {
        let v = UIButton()
        v.setBackgroundImage(UIImage(named: "search_ri"), for: .normal)
        return v
    } ()
    lazy var backButton: DynBackButton = {
        let v = DynBackButton()
        return v
    } ()
    var searchingS = false
    func setSearchStatus() {
        if searchingS {
            titleLab.isHidden = true
            searchBg.isHidden = false
            searchButton.setBackgroundImage(UIImage(named: "fanhui"), for: .normal)

        } else {
            titleLab.isHidden = false
            searchBg.isHidden = true
            searchButton.setBackgroundImage(UIImage(named: "search_ri"), for: .normal)

        }
    }
    var searchChange:((Bool)->())?
    override init(frame: CGRect) {
        super.init(frame: frame)
  
  
       
        addSubview(titleLab)
        addSubview(backButton)

        addSubview(searchBg)

        addSubview(searchButton)
        searchButton.addTouchUpInSideAction { _ in
            self.searchingS = !self.searchingS
            self.setSearchStatus()
            if let clo = self.searchChange {
                clo(self.searchingS)
            }
        }
       
       titleLab.snp.makeConstraints { make in
           make.center.equalToSuperview()
        }
    
        backButton.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(12)
            make.height.equalTo(31)
            make.width.equalTo(33)

            make.centerY.equalToSuperview()
        }
        searchButton.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-10)
            make.width.height.equalTo(30)
            make.centerY.equalToSuperview()
        }
 
        searchBg.isHidden = true
        searchBg.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(45)
            make.right.equalToSuperview().offset(-45)
            make.centerY.equalToSuperview()
            make.height.equalTo(38)

        }
       
  
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
class DynBackButton:UIButton {
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.setImage(UIImage(named: "nav_com_back"), for: .normal)

    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        imageView?.frame = CGRect(x: 2, y: 5, width: self.ks_width - 18, height: self.ks_height - 10)
    }
}
